var fs = require("fs");
var path = require("path");

function readFile(filename) {
  let file = path.join(__dirname, "../config/", filename);
  var cookieString = fs.readFileSync(file, "utf8");
  return cookieString;
}

exports.readCookieTxt = function(filename) {
  let cookieString = readFile(filename);
  let cookieArray = [];

  let array = cookieString.split(";");
  for (const item of array) {
    if (item) {
      const temp = item.split("=");
      if (temp) {
        const name = temp[0].trim();
        const value = temp[1].trim();
        cookieArray.push({
          name: name,
          value: value,
          domain: ".taobao.com",
          path: "/"
        });
      }
    }
  }
  return cookieArray;
};
